package com.googlecode.nls4j.benchmarks.text;

import java.util.EnumSet;
import java.util.Locale;

import com.googlecode.nls4j.CurrentBundle;
import com.googlecode.nls4j.EnumTextBundleLoader;
import com.googlecode.nls4j.KeyValuePair;
import com.googlecode.nls4j.KeyValuePairStorage;
import com.googlecode.nls4j.NlsContext;
import com.googlecode.nls4j.Text;

public enum Msg implements KeyValuePair<Text> {
    M1("M1 default value"),
    M2("M2 default value"),
    M3("M3 default formatted value: {0}");

    private static final CurrentBundle<Msg, Text> currentBundle = CurrentBundle
            .newInstance(
                NlsContext.getDefault(),
                new KeyValuePairStorage<Msg, Text>(
                        Msg.class,
                        EnumTextBundleLoader.<Msg> getDefault(false), EnumSet
                                .allOf(Msg.class)), false);
    private final Text defaultValue;
    private volatile Text value;

    private Msg(final String defaultValue) {
        this.defaultValue = value = new Text(defaultValue, Locale.ENGLISH);
    }

    public static CurrentBundle<Msg, Text> getCurrentBundle() {
        return currentBundle;
    }

    @Override
    public String getName() {
        return name();
    }

    @Override
    public Text getDefaultValue(final Locale locale) {
        return defaultValue;
    }

    @Override
    public Text getValue() {
        return value;
    }

    @Override
    public void setValue(final Text value) {
        this.value = value;
    }

    public String format(final Object... args) {
        return value.format(args);
    }

    @Override
    public String toString() {
        return value.toString();
    }
}
